package cn.zbzcode.mq._06springboot_mq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class ReceiveHandler {
    //监听email队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receive_email(String msg,Message message,Channel channel) throws IOException {
        System.out.println("receive_email:"+msg);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //手动签收
        channel.basicAck(deliveryTag, false);

    }

    //监听sms队列
    @RabbitListener(queues = {RabbitmqConfig.QUEUE_INFORM_SMS})
    public void receive_sms(String msg, Message message, Channel channel) throws IOException {
        System.out.println("receive_sms:"+msg);
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        //手动签收
        channel.basicAck(deliveryTag,false);
    }
} 